<?php 
declare (strict_types = 1);
namespace app\api\controller;
use app\common\controller\Api;
use think\Request;
class BusinessHostLog extends Api
{
    protected $with = ['business_host'];
    //主持人记录-列表
    public function index()
    {
        $this->businessCheckLogin();
        $limit = input('limit') ?: 20;
        $date = input('date');
        $where = [
            ['business_id','=',$this->businessinfo['id']]
        ];
        if($date){
            $date = explode('到',$date);
            $where[] = ['date','>=',trim($date[0])];
            $where[] = ['date','<=',trim($date[1])];
        }
        $id = input('id');
        if($id){
            $where[] = ['business_host_id','=',$id];
        }
        $data = $this->model->where($where)->with($this->with)->order('date desc,id desc')->paginate($limit);
        return datasuccess($data);
    }

    //主持人记录-添加
    public function add()
    {
        $this->businessCheckLogin();
        $post = param();
        if(!empty($post)){
            $post['business_id'] = $this->businessinfo['id'];
            $this->model->save($post);
            return datasuccess();
        }else{
            return msgerror('参数缺失');
        }
    }
}